// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	2/13/2015 8:26:02 PM				
// -----------------------------

#include "Timer.h"

namespace Flow
{

	Timer::Timer()
		: m_uFrequency(0)
		, m_uStartTime(0)
		, m_uLastTime(0)
		, m_uThisTime(0)
	{
	}
	Timer::Timer(const Timer& refTimer)
		: m_uFrequency(refTimer.m_uFrequency)
		, m_uStartTime(refTimer.m_uStartTime)
		, m_uLastTime(refTimer.m_uLastTime)
		, m_uThisTime(refTimer.m_uThisTime)
	{
	}
	Timer& Timer::operator=(const Timer& refTimer)
	{
		m_uFrequency = refTimer.m_uFrequency;
		m_uStartTime = refTimer.m_uStartTime;
		m_uLastTime = refTimer.m_uLastTime;
		m_uThisTime = refTimer.m_uThisTime;

		return (*this);
	}
	Timer::~Timer()
	{
	}

	void Timer::Reset()
	{
		QueryPerformanceFrequency((LARGE_INTEGER*)&m_uFrequency);

		QueryPerformanceCounter((LARGE_INTEGER*)&m_uStartTime);
		m_uLastTime = m_uStartTime;
		m_uThisTime = m_uStartTime;
	}
	void Timer::Update()
	{
		m_uLastTime = m_uThisTime;
		QueryPerformanceCounter((LARGE_INTEGER*)&m_uThisTime);
	}

	Float Timer::GetElapsedTime() const
	{
		return ConvertToSeconds(m_uThisTime - m_uStartTime);
	}
	Float Timer::GetDeltaTime() const
	{
		return ConvertToSeconds(m_uThisTime - m_uLastTime);
	}

	Float Timer::ConvertToSeconds(UInt64 ticks) const
	{
		return (ticks * (1.0f / m_uFrequency));
	}

}